// 该文件专门用于创建整个应用的路由器
import VueRouter from 'vue-router'
import store from '@/store/store';
// export default new VueRouter({
//     routes:[
//         {
//             path: '/',
//             redirect: '/login'
//         },
//         {
//             path: '/login',
//             name: '登陆页',
//             component: ()=>import('@/components/Login.vue')
//         },
//         {
//             path: '/home',
//             name: '主页',
//             component: ()=>import('@/components/Home.vue'),
//             children:[
//                 {
//                     path: '/user',
//                     name: '员工管理',
//                     component: ()=>import('@/components/user/User.vue'),
//                 },
//                 {
//                     path: '/userAddFrom',
//                     name: '新增员工表单',
//                     component: ()=>import('@/components/user/form.vue'),
//                 },
//                 {
//                     path: '/403',
//                     name: '403',
//                     component: ()=>import('@/components/403.vue')
//                 }
//             ]
//         }
//     ],
// })

const router = new VueRouter({
        routes:[
            {
                path: '/',
                redirect: '/login'
            },
            {
                path: '/login',
                name: '登陆页',
                component: ()=>import('@/components/Login.vue')
            },
            {
                path: '/home',
                name: '主页',
                component: ()=>import('@/components/Home.vue'),
                children:[
                    {
                        path: '/user',
                        name: '员工管理',
                        component: ()=>import('@/components/user/User.vue'),
                        meta:{isAuth:true}
                    },
                    {
                        path: '/userAddFrom',
                        name: '新增员工表单',
                        component: ()=>import('@/components/user/Form.vue'),
                        meta:{isAuth:true}
                    },
                    {
                        path: '/category',
                        name: '餐品类别',
                        component: ()=>import('@/components/eat/Category.vue')
                    },
                    {
                        path: '/flavor',
                        name: '口味管理',
                        component: ()=>import('@/components/eat/Flavor.vue')
                    },
                    {
                        path: '/dish',
                        name: '菜品管理',
                        component: ()=>import('@/components/eat/Dish.vue')
                    },
                    {
                        path: '/meal',
                        name: '套餐管理',
                        component: ()=>import('@/components/eat/Meal.vue')
                    },
                    {
                        path: '/carousel',
                        name: '轮播图管理',
                        component: ()=>import('@/components/setting/Carousel.vue')
                    },
                    {
                        path: '/dataCount',
                        name: '数据统计',
                        component: ()=>import('@/components/data/DataCount.vue')  
                    },
                    {
                        path: '/room',
                        name: '餐位管理',
                        component: ()=>import('@/components/room/Room.vue')
                    },
                    {
                        path: '/order',
                        name: '套餐管理',
                        component: ()=>import('@/components/order/Order.vue')
                    },
                    {
                        path: '/429',
                        name: '请求过频繁页面',
                        component: ()=>import('@/components/429.vue')
                    },
                ]
            }
        ]
})

//全局前置路由守卫————初始化的时候被调用、每次路由切换之前被调用
router.beforeEach((to,from,next)=>{
	// console.log('前置路由守卫',to,from)
	if(to.meta.isAuth){ //判断是否需要鉴权
        let Root_Stop = store.getters.getRoot;
        // console.log("ok:"+ store.getters.getStop)
        Root_Stop.stop = new Number(Root_Stop.stop)
        Root_Stop.isRoot = new Number(Root_Stop.isRoot)
        // console.log("stop"+Root_Stop.stop+","+Object.prototype.toString.call(Root_Stop.stop))
        // console.log("root"+Root_Stop.isRoot+","+Object.prototype.toString.call(Root_Stop.isRoot))
		if( Root_Stop.stop == 0){
            if( Root_Stop.isRoot == 0) {
                // console.log("账号正常使用，您有权限访问。")
                next()
            }else{
                // console.log("您没有权限访问。")
            }
		}else{
			// console.log('账号已经被禁用！')
            // router.push('/403')
            alert("账号已经被禁用！")
		}
	}
    next()
})

//全局后置路由守卫————初始化的时候被调用、每次路由切换之后被调用
router.afterEach((to,from)=>{
	document.title = to.meta.title || '餐饮信息系统'
})

export default router